import Taro from '@tarojs/taro'

const prefix = 'http://127.0.0.1:7001'

export default () => {
  // 登录
  return Taro.login().then(results => {
    const { code } = results
    return Taro.getUserInfo().then(result => {
      const { userInfo } = result

      // 发送请求
      return Taro.request({
          url: `${prefix}/api/v1/access/weapp/${code}`,
          method: 'GET',
          header: { 'content-type': 'application/json' }
        })
        .then(res => {
          const { data = {} } = res || {}
          console.log(res, 'mylogin')
          Taro.setStorage({
            key: 'getUserInfo',
            data: { ...userInfo, nickname: userInfo.nickName, status: 0, code, ...data.data }
          })
        })

    })
  })
}